package com.kobe.system.service.impl;

import com.kobe.system.domain.SysKobeDetail;
import com.kobe.system.domain.SysKobeFinance;
import com.kobe.system.mapper.SysKobeFinanceMapper;
import com.kobe.system.service.SysKobeFinanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class SysKobeFinanceServiceImpl implements SysKobeFinanceService {
    @Autowired
    SysKobeFinanceMapper sysKobeFinanceMapper;


    @Override
    public void add(SysKobeFinance sysKobeFinance) {
        sysKobeFinanceMapper.addSysKobeFinance(sysKobeFinance);
    }

    @Override
    public List<SysKobeFinance> listFinance(SysKobeFinance sysKobeFinance) {
        return sysKobeFinanceMapper.listFinance(sysKobeFinance);
    }

    @Override
    public SysKobeFinance getFinanceById(Long financeId) {
        return sysKobeFinanceMapper.getFinanceById(financeId);
    }

    @Override
    public List<SysKobeDetail> getDetailById(Long financeId) {
        return sysKobeFinanceMapper.getDetailById(financeId);
    }

    @Override
    public List<SysKobeFinance> getFinanceByProjectId(Long projectId) {
        return sysKobeFinanceMapper.getFinanceByProjectId(projectId);
    }

    @Override
    public Double getProjectComeMoneyById(Long projectId) {
        return sysKobeFinanceMapper.getProjectComeMoneyById(projectId);
    }

    @Override
    public Double getProjectOutMoneyById(Long projectId) {
        return sysKobeFinanceMapper.getProjectOutMoneyById(projectId);
    }



    @Override
    public void updateFinance(SysKobeFinance sysKobeFinance) {

        sysKobeFinanceMapper.getDetailById(sysKobeFinance.getFinanceId()).forEach(detail -> {
            sysKobeFinanceMapper.deleteSysKobeDetail(detail.getFinanceId());
        });

        sysKobeFinanceMapper.updateSysKobeFinance(sysKobeFinance);

    }

    @Override
    public void deleteFinanceById(Long projectId) {
        sysKobeFinanceMapper.deleteFinanceById(projectId);
    }

    @Override
    public void addDetail(SysKobeDetail detail) {
        sysKobeFinanceMapper.addDetail(detail);
    }

}
